<template>
  <div id="globaHeader">
    <a-row :wrap="false">
      <a-col flex="200px">
        <div class="tltle-bar">
          <img class="logo" src="@/assets/logo4.png" alt="logo" />
          <div class="tltle">UHub+</div>
        </div>
      </a-col>
      <a-col flex="auto">
        <a-menu
          v-model:selectedKeys="current"
          mode="horizontal"
          :items="items"
          @click="doMenuClick"
        />
      </a-col>
      <a-col flex="80px"
        ><div class="user-login-sttatus">
          <div class="userName" v-if="loginUserStore.loginUser.id">
            {{
              loginUserStore.loginUser.username ||
              "代号-" + loginUserStore.loginUser.planetCode
            }}
            <a-avatar size="small" style="background-color: #7265e6">
              {{ loginUserStore.loginUser.userAccount }}
            </a-avatar>
          </div>
          <div v-else>
            <a-button
              type="primary"
              @click="route.push({ path: '/user/login', replace: true })"
              >登录</a-button
            >
          </div>
        </div>
      </a-col>
    </a-row>
  </div>
</template>
<script lang="ts" setup>
import { h, ref, watch } from "vue";
import {
  HomeOutlined,
  CrownOutlined,
  GithubOutlined,
} from "@ant-design/icons-vue";
import { MenuProps } from "ant-design-vue";
import { useRouter } from "vue-router";
import { useLoginUserStore } from "@/store/useLoginUserStore";
const route = useRouter();

const current = ref([route.currentRoute.value.path]);
const loginUserStore = useLoginUserStore();

watch(
  () => route.currentRoute.value.path,
  (newPath) => {
    current.value = [newPath];
  },
  { immediate: true }
);

const doMenuClick = ({ key }: { key: string }) => {
  route.push({
    path: key,
  });
};
const items = ref<MenuProps["items"]>([
  {
    key: "/",
    icon: () => h(HomeOutlined),
    label: "主页",
    title: "主页",
  },
  {
    key: "/user/login",
    label: "用户登录",
    title: "用户登录",
  },
  {
    key: "/user/register",
    label: "用户注册",
    title: "用户注册",
  },
  {
    key: "/admin/userManage",
    icon: () => h(CrownOutlined),
    label: "用户管理",
    title: "用户管理",
  },
  {
    key: "Gitee",
    // icon: () => h(GithubOutlined),
    label: h(
      "a",
      {
        href: "https://gitee.com/xiefolin/user-center-frontend-vue",
        target: "_blank",
      },
      "GitHub"
    ),
    title: "GitHub",
  },
]);
</script>

<style lang="scss" scoped>
#globaHeader {
  .tltle-bar {
    display: flex;
    align-self: center;
    .logo {
      height: 48px;
    }
    .tltle {
      margin-left: 16px;
      font-size: 18px;
      color: rgb(173, 237, 255);
      font-weight: bold;
    }
  }
  .userName {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}
</style>
